//
//  ZYAlertController.m
//  LinLiSheQu
//
//  Created by 郭树清 on 2018/5/8.
//  Copyright © 2018年 KuoShuChing. All rights reserved.
//

#import "ZYAlertController.h"

@interface ZYAlertController ()

@end

@implementation ZYAlertController

- (void)viewDidLoad{
    [super viewDidLoad];
}

+ (void)userAlertControllerWithTitleName:(NSString *)titleName andMessage:(NSString *)message addcancelButtonTitle:(NSString*)cancelButtonTitle adotherTitle:(NSString*)buttonTitle showViewController:(UIViewController*)currentVC addCancelClickBlock:(CancelButtonBlock)cancelBlock addotherClickBlock:(SureButtonBlock)SureBlock{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:titleName message:message preferredStyle:UIAlertControllerStyleAlert];
    //改变title的大小和颜色
    NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleName];
    [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, titleName.length)];
    [titleAtt addAttribute:NSForegroundColorAttributeName value:Color_33 range:NSMakeRange(0, titleName.length)];
    [alertController setValue:titleAtt forKey:@"attributedTitle"];
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, message.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:Color_33 range:NSMakeRange(0, message.length)];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];
  
    if (buttonTitle) {
        //按钮
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            SureBlock(action);
        }];
        [alertAction setValue:UIColorFromRGB(0xFF8900) forKey:@"_titleTextColor"];
        //    alertController.view.tintColor = [UIColor greenColor];
        [alertController addAction:alertAction];
    }
    if (cancelButtonTitle) {
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            //        exit(0);
            cancelBlock(action);
        }];
        /*取消按钮的颜色*/
        [cancel setValue:Color_99 forKey:@"_titleTextColor"];
        [alertController addAction:cancel];
        
    }

    [currentVC presentViewController:alertController animated:YES completion:nil];
}

@end
